import pandas as pd

# 读取Excel文件中的两个Sheet
file_path = 'F:\\检查员分级筛选名单20250302(1).xlsx'
sheet1_name = '专家级'
sheet2_name = '专家17'

# 读取Sheet1和Sheet2的数据
df1 = pd.read_excel(file_path, sheet_name=sheet1_name)
df2 = pd.read_excel(file_path, sheet_name=sheet2_name)
# 检查索引和列标签是否一致
if not df1.index.equals(df2.index) or not df1.columns.equals(df2.columns):
    print("DataFrame 的索引或列标签不一致")

    # 重置索引
    df1 = df1.reset_index(drop=True)
    df2 = df2.reset_index(drop=True)

    # 确保列标签一致
    df1.columns = df2.columns
# 比对两个DataFrame的差异
diff = df1.compare(df2)

# 输出差异
print("Differences between Sheet1 and Sheet2:")
print(diff)

# 如果需要将差异保存到新的Excel文件
output_file_path = 'F:\\differences.xlsx'
diff.to_excel(output_file_path, engine='openpyxl')
print(f"Differences saved to {output_file_path}")
